package HighLevelFunction

object HighLeveFunction_Reduce {
  def main(args: Array[String]): Unit = {
    //规约简化操作reduce
    val list=List(1,2,3,4)
    val sum: Int = list.reduce((a: Int, b: Int) => {
      a + b
    })
    println(sum)
    println(list.sum)
    println(list.reduceLeft(_+_))
    println(list.reduceRight(_+_))
    //当reduceRight相加减时，是从右往左两个连个进行递归调用
    //1-（2-（3-（4-5）））
    println("==============================")
    val foldList: Int = list.fold(10)(_ + _)
    println(foldList)
    println(list.foldLeft(10)(_-_))
    println(list.foldRight(11)(_-_))

  }

}
